package com.hiof.servercommunication.background.job;

import com.hiof.location.GPSManager;
import com.hiof.location.GpsMangerFactory;
import com.hiof.servercommunication.RestFulServiceManager;
import com.hiof.servercommunication.exception.NetworkException;
import com.hiof.servercommunication.exception.ServerException;
import com.hiof.servercommunication.receive.beans.AcknowledgePacket;
import com.hiof.servercommunication.receive.beans.GeoPoint;
import com.hiof.servercommunication.receive.beans.Packet;
import com.hiof.settings.SettingManager;
import com.hiof.settings.user.TypeOfAttendant;
import com.hiof.settings.user.UserConfiguration;
import com.hiof.utility.Utility;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 6/22/12
 * Time: 1:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class AthleteHeartRateSendJob  extends AbstractJob {

    @Override
    public Packet connect2Server() {
        int athleteId = UserConfiguration.getInstance().getAttendantId();
        AcknowledgePacket acknowledgePacket = new AcknowledgePacket("ok");
        try {
            int heartRate = SettingManager.getInstance().getCurrentHeartRate();
                acknowledgePacket = RestFulServiceManager.getInstance().sendAthleteHeartRate(athleteId, heartRate);
        } catch (NetworkException e) {
            Utility.error(this.getClass().toString(), "NetworkException when sending Live Location:" + e.getMessage());
            acknowledgePacket.setMessage("Network Exception");
        } catch (ServerException e) {
            Utility.error(this.getClass().toString(),"ServerException when sending Live Location:"+e.getMessage());
            acknowledgePacket.setMessage("Server Exception");
        }
        Utility.debug(this.getClass().toString(),"packet:"+acknowledgePacket.getMessage());
        return acknowledgePacket;
    }
}